﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace winform基础学习
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Login_Click(object sender, EventArgs e)
        {
            string userName = username.Text;
            string passWord = password.Text;

            if (string.IsNullOrEmpty(userName))
            {
                MessageBox.Show("请输入用户名！");
                return;
            }

            if (string.IsNullOrEmpty(passWord))
            {
                MessageBox.Show("请输入密码！");
                return;
            }
            UserTModel model = null;
            using (MyDbContext dbContext = new MyDbContext())
            {
                model = dbContext.userTModels.FirstOrDefault(x => x.UserName == userName && x.PassWord == passWord);
            }

            if (model==null)
            {
                MessageBox.Show("用户名或密码错误！");
                return;
            }
            else
            {
                MessageBox.Show("登录成功！");
                Index index = new Index(model);
                index.Show();
                this.Hide();
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {
            RegisterForm registerForm = new RegisterForm();
            registerForm.ShowDialog();
        }
    }
}
